package com.ts.api.http.market.channel;

import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarket;
import com.ts.api.module.api.convert.core.annotation.ApiChannelMarketConvertType;
import com.ts.api.module.api.convert.core.entity.ApiBizStatus;
import com.ts.api.module.api.convert.market.entity.ChannelMarketParameter;
import com.ts.api.module.api.convert.market.handler.ChannelMarketConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;

import java.util.Map;

/**
 * 树融
 * 联登不撞库卖量：https://www.showdoc.com.cn/p/5f5902236e6fe157f875efb123567391
 *
 * @author WJB
 */
@ApiChannelMarket(uniqueCode = "9a27510aa073480c806257039b1def28", type = ApiChannelMarketConvertType.FEDERATE_LOGIN)
public class ShuRongFederate implements ChannelMarketConvertHandler {

    @Override
    public ApiUserRequest parse(RequestVO requestVO) {
        String phone = requestVO.getStr("phone");

        ApiUserRequest apiUserRequest = new ApiUserRequest();
        apiUserRequest.setPhone(phone);
        return apiUserRequest;
    }

    @Override
    public Map<String, Object> response(ChannelMarketParameter channelMarketParameter, ApiBizStatus apiBizStatus) {
        if (apiBizStatus.hasBizSuc()) {
            return MapUtils.newHashMap(newMap -> {
                newMap.put("code", 200);
                newMap.put("message", apiBizStatus.getBizMsg());
                newMap.put("data", MapUtils.newLinkedHashMap(dataMap -> {
                    dataMap.put("url", channelMarketParameter.getUrl());
                }));
            });
        }

        return MapUtils.newHashMap(newMap -> {
            newMap.put("code", 500);
            newMap.put("message", apiBizStatus.getBizMsg());
        });
    }

}
